<template>
	<view>
		<view class="pay_zhifu_type">
			<view class="head">支付方式</view>
			<radio-group @change="changeCurr">
				<label class="pay_zhifu_item" v-for="(item, index) in items" :key="item.value">
					<view class="pay_zhifu_status_type">
						<text class="iconfont icon" :class="{'icon-weixin':item.value==1,'icon-zhifubao':item.value==2,'icon-yinhangka_mian':item.value==0}"></text>
						<text>{{item.name}}</text>
					</view>
					<view>
						<radio class="withdrawal_status_radio" color="#8615E1" :value="item.value" :checked="item.value == current" />
					</view>
				</label>
			</radio-group>
		</view>
		<view class="pay_tip">
			微信限额单笔交易1000以内<br>支付宝限额单笔交易10000以内 
		</view>
		<!-- <view class="totalBtn" @click="submit">去支付</view> -->
	</view>
</template>

<script>
	import Base64 from 'base-64';
	export default {
		data() {
			return {
				items: [{
					value: '1',
					name: '微信',
					checked: true
				},{
					value: '2',
					name: '支付宝',
					checked: true
				}],
				current: 0,
				content: '',
				sig: '',
				mid: 0,
				code: '',
			}
		},
		onLoad(option){
			if (option.q) {
				let scan_url = decodeURIComponent(option.q);
				this.content = this.gup('content', scan_url);
				this.sig = this.gup('sig', scan_url);
			} else {
				this.content = option.content;
				this.sig = option.sig;
			}
			this.content = this.content.replace('=','');
			
			uni.setStorageSync('mid', Base64.decode(this.content));
			this.mid=Base64.decode(this.content);
			if(option.code){
				this.code = option.code;
			}
			this.getinfo();
			// if(!uni.getStorageSync('token')){
			// 	this.getToken();
			// }else{
			// 	this.getinfo();
			// }
		},
		methods: {
			getinfo() {
				var that = this;
				uni.showLoading({
					title: '加载中'
				})
				this.$axios('paytrans/display', 'POST', 'order', {
					content: this.content,
					sig: this.sig
				}).then(res => {
					uni.hideLoading();
					if (res.data.code == 200) {
						this.info = res.data.data;
						// this.getDisInfo(this.info.uid);
					}
				})
			},
			submit(){
				console.log(this.sig)
				if(this.current==1){
					let obj = {
						content: this.content,
						sig: this.sig
					}
					let queryString = Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&')
					const res = encodeURIComponent(queryString)
					window.location.href= `weixin://dl/business/?appid=wx3e16600b89504d0f&path=pages/business/accounts&query=`+res
					// window.location.href= `weixin://dl/business/?appid=wx4cbf847f4c621150&path=pages/business/accounts?content=`+this.content+`&sig=`+this.sig
					// window.location.href= "weixin://dl/business/?appid=wx4cbf847f4c621150&path=pages/mallHome/selfMall?mid=222"
				}else{
					console.log(this.sig)
					// return;
					this.$navTo('https://bph5.jinghushi.com/?content='+this.content+'&sig='+this.sig)
					// this.$navTo('http://localhost:8080/?content='+this.content+'&sig='+this.sig)
				}
			},
			
			changeCurr(e){
				console.log(e)
				this.current = e.detail.value;
				if(this.current==1){
					let obj = {
						content: this.content,
						sig: this.sig
					}
					let queryString = Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&')
					const res = encodeURIComponent(queryString)
					window.location.href= `weixin://dl/business/?appid=wx3e16600b89504d0f&path=pages/business/accounts&query=`+res
					// window.location.href= `weixin://dl/business/?appid=wx4cbf847f4c621150&path=pages/business/accounts?content=`+this.content+`&sig=`+this.sig
					// window.location.href= "weixin://dl/business/?appid=wx4cbf847f4c621150&path=pages/mallHome/selfMall?mid=222"
				}else{
					console.log(this.sig)
					// return;
					this.$navTo('https://bph5.jinghushi.com/?content='+this.content+'&sig='+this.sig)
					// this.$navTo('http://localhost:8080/?content='+this.content+'&sig='+this.sig)
				}
			},
			getToken(){
				this.$axios('login/autoGzlogin','POST','member',{
					mid: this.mid,
					code: this.code,
					content: this.content,
					sig: this.sig
				}).then(res=>{
					if(res.data.code == 300001){
						this.$navTo(res.data.data);
					}else if(res.data.code == 200){
						uni.setStorageSync('token', res.data.data);
						uni.setStorageSync('Jh_recotabshops', 1);
						this.getinfo();
					}
				})
							
			},
		}
	}
</script>

<style lang="scss">
	@import '/store/icon.css';
	.pay_zhifu_type{
		background: #fff;
		margin: 0 10rpx;
		padding: 20rpx;
		.pay_zhifu_item{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 10rpx;
		}
		.pay_zhifu_status_type{
			display: flex;
			align-items: center;
		}
		.pay_zhifu_status_type .icon {
			font-size: 100rpx;
			margin-right: 30rpx;
		}
		.icon-weixin {
			color: #50bb34;
		}
		
		.icon-zhifubao {
			color: #44a9fd;
		}
		.withdrawal_status_radio {
			transform: scale(1.2);
		}
	}
	.pay_tip{
		padding: 20rpx 40rpx;
		color: red;
		line-height: 44rpx;
		color: #e91c1c;
	}
</style>
